<?php


namespace App\Services;


class Uri
{
    /**
     * 生成图片地址的URL地址
     * @param string $path 可选 图片相对路径 不能以 / 头
     */
    public static function createImageUrl($path='') :string {
        $path = $path ?: "/default.png";
        return self::createUploadsUrl($path);
    }

    public static function createVideoUrl($path) :string {
        return self::createUploadsUrl($path);
    }

    public static function createAppUrl($path):string{
        return self::createUploadsUrl($path);
    }

    protected static function getBaseUploadsUrl(){
        return config("filesystems.disks.uploads.url");
    }
    protected static function createUploadsUrl($path){
        if(strpos($path, 'http')===0){
            return $path;
        }
        if(strpos($path, "/")!==0){
            $path = "/".$path;
        }
        return self::getBaseUploadsUrl().$path;
    }
    public static function getFullPath($path) :string {
        $basePath = config("filesystems.disks.uploads.root");
        if(strpos($path, "/")!==0){
            $path = "/".$path;
        }
        return $basePath . $path;
    }

}
